home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- import re
- import libxml2
- from blueprintbase import LPBluePrint
- from lphelper import _gen_getter, user, unicode_for_libxml2
- from lptime import LPTime
- from bugbase import LPBugInfo
- from subscribersbase import LPSubscribers
-
- def _get_content(xml, path):
- x = xml.xpathEval(path)
- if not x:
- raise AssertionError
- res = x[0].content.strip('\n ')
- x = res.split('\n')
- return res
-
-
- def _get_user(xml, path):
- m = xml.xpathEval(path)
- if m:
- return user.parse_html_user(m[0])
- m = xml.xpathEval('td')
- if not m:
- raise AssertionError
- if not 'None' in m[0].content:
- raise AssertionError
- return user(None)
-
-
- class InfoBox(object):
-
- def __init__(self, xml):
- self.xmldoc = xml[0]
- self.parsed = False
- self._InfoBox__priority = None
- self._InfoBox__status = None
- self._InfoBox__delivery = None
- self._InfoBox__goal = None
- self._InfoBox__assignee = user(None)
- self._InfoBox__drafter = user(None)
- self._InfoBox__approver = user(None)
- self._InfoBox__sprints = set()
-
-
- def parse(self):
- if self.parsed:
- return True
- rows = self.xmldoc.xpathEval('tr')
- for row in rows:
- if row.xpathEval('th[contains(.,"Priority")]'):
- if not not (self._InfoBox__priority):
- raise AssertionError
- self._InfoBox__priority = _get_content(row, 'td')
- continue
- not (self._InfoBox__priority)
- if row.xpathEval('th[contains(.,"Definition")]'):
- if not not (self._InfoBox__status):
- raise AssertionError
- self._InfoBox__status = _get_content(row, 'td')
- continue
- not (self._InfoBox__status)
- if row.xpathEval('th[contains(.,"Implementation")]'):
- if not not (self._InfoBox__delivery):
- raise AssertionError
- self._InfoBox__delivery = _get_content(row, 'td')
- continue
- not (self._InfoBox__delivery)
- if row.xpathEval('th[contains(.,"Series goal")]'):
- if not not (self._InfoBox__goal):
- raise AssertionError
- self._InfoBox__goal = _get_content(row, 'td')
- continue
- not (self._InfoBox__goal)
- if row.xpathEval('th[contains(.,"Assignee")]'):
- if not not (self._InfoBox__assignee):
- raise AssertionError
- self._InfoBox__assignee = _get_user(row, 'td/a')
- continue
- not (self._InfoBox__assignee)
- if row.xpathEval('th[contains(.,"Drafter")]'):
- if not not (self._InfoBox__drafter):
- raise AssertionError
- self._InfoBox__drafter = _get_user(row, 'td/a')
- continue
- not (self._InfoBox__drafter)
- if row.xpathEval('th[contains(.,"Approver")]'):
- if not not (self._InfoBox__approver):
- raise AssertionError
- self._InfoBox__approver = _get_user(row, 'td/a')
- continue
- not (self._InfoBox__approver)
- if row.xpathEval('th[contains(.,"Sprints")]'):
- m = row.xpathEval('td//a')
- for i in m:
- self._InfoBox__sprints.add(i.content)
-
- self.parsed
- if not None:
- raise AssertionError, 'unknown attribute in InfoBox: %s' % row.xpathEval('th').content
-
- self.parsed = True
-
-
- def priority(self):
- return self._InfoBox__priority
-
- priority = property(priority)
-
- def status(self):
- return self._InfoBox__status
-
- status = property(status)
-
- def delivery(self):
- return self._InfoBox__delivery
-
- delivery = property(delivery)
-
- def assignee(self):
- return self._InfoBox__assignee
-
- assignee = property(assignee)
-
- def drafter(self):
- return self._InfoBox__drafter
-
- drafter = property(drafter)
-
- def approver(self):
- return self._InfoBox__approver
-
- approver = property(approver)
-
- def sprints(self):
- return self._InfoBox__sprints
-
- sprints = property(sprints)
-
-
- class Subscribers(LPSubscribers):
-
- def __init__(self, xml):
- self.parsed = False
- self.xmldoc = xml
- LPSubscribers.__init__(self, ('essential', 'inessential'))
-
-
- def parse(self):
- if self.parsed:
- return True
- for i in self.xmldoc:
- m = i.xpathEval('a')
- if not m:
- raise AssertionError
- x = user.parse_html_user(m[0])
- m = i.xpathEval('img')
- if not m:
- raise AssertionError
- if 'inessential' in m[0].prop('src'):
- self['inessential'].add(x)
- continue
- m
- if 'essential' in m[0].prop('src'):
- self['essential'].add(x)
- continue
- m
- if not None:
- raise AssertionError, 'unsupported type'
-
- self.parsed = True
-
-
- def add(self):
- raise NotImplementedError, 'read-only'
-
-
-
- class Lifecycle(object):
-
- def __init__(self, xml):
- self.xmldoc = xml[0]
- self.parsed = False
- self.registrant = user(None)
- self.date_registered = None
- self.starter = user(None)
- self.date_started = None
- self.completer = user(None)
- self.date_completed = None
-
-
- def parse(self):
- if self.parsed:
- return True
- rows = self.xmldoc.xpathEval('tr')
- for row in rows:
- if row.xpathEval('th[contains(.,"Registered by")]'):
- if not not (self.registrant):
- raise AssertionError
- self.registrant = _get_user(row, 'td/a')
- continue
- not (self.registrant)
- if row.xpathEval('th[contains(.,"When")]'):
- if not not (self.date_registered):
- raise AssertionError
- x = _get_content(row, 'td/span/@title')
- self.date_registered = LPTime(x)
- continue
- not (self.date_registered)
- if row.xpathEval('th[contains(.,"Started")]'):
- if not not (self.date_started):
- raise AssertionError
- x = _get_content(row, 'td')
- self.date_started = LPTime(x)
- continue
- not (self.date_started)
- if row.xpathEval('th[contains(.,"Completed")]'):
- if not not (self.date_completed):
- raise AssertionError
- x = _get_content(row, 'td')
- self.date_completed = LPTime(x)
- continue
- not (self.date_completed)
- if row.xpathEval('th[contains(.,"by")]'):
- i = row.xpathEval('preceding-sibling::tr/th')
- if not i:
- raise AssertionError
- if 'started' in i[-1].content.lower():
- if not not (self.starter):
- raise AssertionError
- self.starter = _get_user(row, 'td/a')
- elif 'completed' in i[-1].content.lower():
- if not not (self.completer):
- raise AssertionError
- self.completer = _get_user(row, 'td/a')
- elif not None:
- raise AssertionError, 'wrong xpath'
- i
- continue
- self.parsed
- if not None:
- raise AssertionError, 'unknown attribute in InfoBox: %s' % row.xpathEval('th').content
-
- self.parsed = True
-
-
-
- class BugInfo(LPBugInfo):
-
- def __init__(self, nr, url, summary):
- LPBugInfo.__init__(self, nr, url, None, None, summary, None, False)
-
-
- def __str__(self):
- return '[Bug %s]' % self.url
-
-
-
- class RelatedBugs(set):
-
- def __init__(self, xml):
- self.xmldoc = xml
- self.parsed = False
- set.__init__(self)
-
-
- def parse(self):
- if self.parsed:
- return True
- for i in self.xmldoc:
- m = i.xpathEval('a')
- if not m:
- raise AssertionError
- u = m[0].prop('href')
- nr = int(u.split('/').pop())
- s = m[0].content.split(':').pop()
- summary = s.strip('\n ')
- self.add(BugInfo(nr, u, summary))
-
- self.parsed = True
-
-
-
- class Overview(object):
-
- def __init__(self, xml):
- self.xmldoc = xml
- self.parsed = False
-
-
- def parse(self):
- if self.parsed:
- return True
- if not self.xmldoc:
- raise AssertionError
- self.text = self.xmldoc[0].content
- self.parsed = True
-
-
-
- class FullSpec(object):
-
- def __init__(self, xml):
- self.xmldoc = xml
- self.parsed = False
-
-
- def parse(self):
- if self.parsed:
- return True
- if not self.xmldoc:
- raise AssertionError
- self.url = self.xmldoc[0].prop('href')
- self.parsed = True
-
-
-
- class Mentors(set):
-
- def __init__(self, xml):
- self.xmldoc = xml
- self.parsed = False
- set.__init__(self)
-
-
- def parse(self):
- if self.parsed:
- return True
- for i in self.xmldoc:
- x = user.parse_html_user(i)
- self.add(x)
-
- self.parsed = True
-
-
-
- class WhiteBoard(object):
-
- def __init__(self, xml):
- self.xmldoc = xml
- self.parsed = False
- self.text = ''
-
-
- def parse(self):
- if self.parsed:
- return True
- if self.xmldoc:
- self.text = self.xmldoc[0].content
-
- self.parsed = True
-
-
-
- class _Request(object):
-
- def __init__(self, user, target, text):
- self.user = user
- self.target = target
- self.text = text
-
-
- def __repr__(self):
- return "<FeedbackRequest from '%s' to '%s'>" % (self.user, self.target)
-
-
-
- class FeedbackRequest(list):
-
- def __init__(self, xml):
- self.xmldoc = xml
- self.parsed = False
- list.__init__(self)
-
-
- def parse(self):
- if self.parsed:
- return True
- for i in self.xmldoc:
- m = i.xpathEval('a')
- if not m:
- raise AssertionError
- r_user = user.parse_html_user(m[0])
- m = i.xpathEval('strong/a')
- if not m:
- raise AssertionError
- r_target = user.parse_html_user(m[0])
- m = i.xpathEval('div[@style="font-style: italic;"]')
- if not m:
- raise AssertionError
- r_text = m[0].content
- self.append(_Request(r_user, r_target, r_text))
-
- self.parsed = True
-
-
-
- class Blueprint(LPBluePrint):
-
- def __init__(self, url, connection):
- LPBluePrint.__init__(self, url, connection)
- page = self._connection.get(self.url)
- self.xmldoc = libxml2.htmlParseDoc(unicode_for_libxml2(page.text), 'UTF-8')
- self._Blueprint__info_box = InfoBox(self.xmldoc.xpathEval('//table[@class="summary"]/tbody'))
- self._Blueprint__subscribers = Subscribers(self.xmldoc.xpathEval('//div[@id="portlet-subscribers"]/div[@class="portletBody"]//div'))
- self._Blueprint__lifecycle = Lifecycle(self.xmldoc.xpathEval('//div[@id="portlet-lifecycle"]/div/table/tbody'))
- self._Blueprint__related_bugs = RelatedBugs(self.xmldoc.xpathEval('//div[@id="portlet-related-bugs"]/div/ul//li'))
- self._Blueprint__overview = Overview(self.xmldoc.xpathEval('//table[@class="summary"]/following-sibling::p[1]'))
- self._Blueprint__full_spec = FullSpec(self.xmldoc.xpathEval('//table[@class="summary"]/following-sibling::ul[1]/li/a'))
- self._Blueprint__mentors = Mentors(self.xmldoc.xpathEval('//table[@class="summary"]/following-sibling::p[2]//a'))
- self._Blueprint__whiteboard = WhiteBoard(self.xmldoc.xpathEval('//h2[contains(.,"Whiteboard")]/following-sibling::div'))
- self._Blueprint__feedback_request = FeedbackRequest(self.xmldoc.xpathEval('//div[@id="portlet-feedback"]/div/ul//li'))
-
- get_priority = _gen_getter('__info_box.priority')
- get_status = _gen_getter('__info_box.status')
- get_delivery = _gen_getter('__info_box.delivery')
- get_assignee = _gen_getter('__info_box.assignee')
- get_drafter = _gen_getter('__info_box.drafter')
- get_approver = _gen_getter('__info_box.approver')
- get_sprints = _gen_getter('__info_box.sprints')
- get_subscribers = _gen_getter('__subscribers')
-
- def get_subscriptions_category(self, type):
- return self._Blueprint__subscribers.get_subscriptions(type)
-
- get_lifecycle = _gen_getter('__lifecycle')
- get_related_bugs = _gen_getter('__related_bugs')
- get_overview = _gen_getter('__overview.text')
- get_full_spec = _gen_getter('__full_spec.url')
- get_mentors = _gen_getter('__mentors')
- get_whiteboard = _gen_getter('__whiteboard.text')
- get_feedback_request = _gen_getter('__feedback_request')
-
- def get_title(self):
- x = self.xmldoc.xpathEval('//div[@class="main"]')
- if not x:
- raise AssertionError
- return x[0].content
-
-
- def get_spec(self):
- return self.url.split('/').pop()
-
-
- def get_project(self):
- x = self.xmldoc.xpathEval('//div[@class="intro"]')
- if not x:
- raise AssertionError
- return x[0].content.split('Blueprint for').pop().strip()
-
-
-